package com.humanmonth.home.component.page.signature
{
	import com.humanmonth.home.component.page.signature.remote.Connector;
	
	import flash.display.BitmapData;
	import flash.events.Event;
	import flash.events.MouseEvent;
	
	import mx.core.Application;
	import mx.events.ColorPickerEvent;
	import mx.events.FlexEvent;
	import mx.events.ListEvent;
	import mx.events.NumericStepperEvent;
	
	/**
	 * 控制面版
	 * @author 林子龙
	 * 
	 */
	public class MyControlBarAs extends MyControlBar
	{
		public var writearea:WriteArea;
		private var connector:Connector=new Connector();
		public function MyControlBarAs()
		{
			super();
			this.addEventListener(FlexEvent.CREATION_COMPLETE,myInit);
		}
		
		private function myInit(event:Event):void{
			this.writearea=Application.application.signature.writearea;
			this.reset.addEventListener(MouseEvent.CLICK,cleanArea);
			this.size.addEventListener(NumericStepperEvent.CHANGE,setLineSize);
			this.color.addEventListener(ColorPickerEvent.CHANGE,setColor);
			this.pattern.addEventListener(ListEvent.CHANGE,setPattern);
			this.savePic.addEventListener(MouseEvent.CLICK,savePicture);
			this.downloadPic.addEventListener(MouseEvent.CLICK,connector.downloadFile)
		}
		/**
		 * 保存图片 
		 */
		private function savePicture(event:Event):void{
			var myData:BitmapData=new BitmapData(this.writearea.width,this.writearea.height);
			myData.draw(this.writearea);
			connector.savePic(myData,enableDownload); 
		}
		
		private function enableDownload(event:Event):void{
			this.downloadPic.enabled=true;
		}
		/**
		 * 设置模式 
		 */
		private function setPattern(event:Event):void{
			this.writearea.pattern=String(this.pattern.value);
		}
		/**
		 * 清空写字区 
		 */
		private function cleanArea(event:Event):void{
			this.writearea.signature.graphics.clear();
		}
		
		/**
		 * 设置线条粗细 
		 */
		public function setLineSize(event:Event):void{
			this.writearea.lineSize=this.size.value;
		}
		
		/**
		 * 设置颜色
		 */
		public function setColor(event:Event):void{
			this.writearea.myColor=uint(this.color.value);
		}
		
		
	}
}